#include "shlwapi.h"
#include "windows.h"

#ifdef _WIN64
LPWSTR scitename = L"SciTE64.exe";
#else
LPWSTR scitename = L"SciTE.exe";
#endif

LPWSTR notepadname = L"notepad_scite64.exe";

INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpszCmdLine, int){
	CONST SIZE_T cBuff = 32768;
	WCHAR szBuff[cBuff];
	
	SIZE_T lenBuff = 0;
	if ((lenBuff = GetEnvironmentVariable(L"SciTE_HOME", szBuff, cBuff)) < cBuff){
		PathAppend(szBuff, scitename);
		if (!PathFileExists(szBuff)){
			lenBuff = 0;
		}
	}
	
	if (lenBuff == 0 && (lenBuff = GetEnvironmentVariable(L"SystemRoot", szBuff, cBuff)) < cBuff){
		PathAppend(szBuff, notepadname);
		if (!PathFileExists(szBuff)){
			lenBuff = 0;
		}
	}

	if (lenBuff){
		ShellExecute(NULL, NULL, szBuff, lpszCmdLine, NULL, 0);
	}

	return 0;
}